//
//  HBQHomeHeaderView.m
//  HelloBeeQuick
//
//  Created by LiYiLin on 16/8/20.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "HBQHomeHeaderView.h"
#import "LYLInfiniteDisplayView.h"
#import "HBQHomeManager.h"
#import "HBQHomeButton.h"
#import "HBQHeaderModel.h"
#import <Masonry/Masonry.h>


#define KInfiniteViewH (self.frame.size.height - 60)
#define KScreenWidth   (self.frame.size.width)
#define KButtonCount 4

@interface HBQHomeHeaderView()<LYLInfiniteDisplayViewDelegate>

//轮播器
@property (nonatomic, strong) LYLInfiniteDisplayView *infiniteView;
//底部按钮
@property (nonatomic, strong) UIView * buttonView;
//轮播器数据
@property (nonatomic, strong) NSArray * infiniteArray;
//按钮数据
@property (nonatomic, strong) NSArray * buttonArray;
//新特惠数据
@property (nonatomic, strong) NSArray * activitesArray;

@end


@implementation HBQHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame {

    if (self= [super initWithFrame:frame]) {
        [self setup_UI];
        [self setup_Layout];
    }
    return self;
}

/*  ============================================================  */

#pragma mark - 重写保存全部数据的titalArray的set方法获得数据 -
- (void)setTotalArray:(NSArray *)totalArray {

    _totalArray = totalArray;
    
    self.infiniteArray = totalArray[0];
    self.buttonArray = totalArray[1];
    self.activitesArray = totalArray[2];
    
    [self loadHomeInfiniteViewWithArray:self.infiniteArray];
    [self loadHomeButtonViewWithArray:self.buttonArray];
}

/*  ============================================================  */

#pragma mark - 配置界面 -
- (void)setup_UI {
    [self addSubview:self.infiniteView];
    [self addSubview:self.buttonView];
    
//    UITapGestureRecognizer *tapGesture = [UITapGestureRecognizer ] ;
}

/*  ============================================================  */

#pragma mark - 约束设置 -
- (void)setup_Layout {
    
    [self.infiniteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(self);
        make.height.mas_equalTo(KInfiniteViewH);
    }];
    
    [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.infiniteView.mas_bottom);
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(self);
    }];
}

/*  ============================================================  */

#pragma mark - 获取界面数据 -
- (void)loadHomeInfiniteViewWithArray:(NSArray *)array {
    
    NSMutableArray * mutable = [NSMutableArray array];
    for (HBQHeaderModel * dic in array) {
        [mutable addObject:dic.img];
        
    }
    self.infiniteView.imageURLStringsGroup = mutable;
}

/*  ============================================================  */

#pragma mark - 设置按钮数据 -
- (void)loadHomeButtonViewWithArray:(NSArray *)array{
    
    for (int i = 0; i < array.count; i++) {
        HBQHomeButton * button = [[HBQHomeButton alloc] init];
        button.frame = CGRectMake(i * KWIDTH / 4, 0, KWIDTH / 4, 50);
        button.iconModel = array[i];
        //将按钮保存到数组中
        [self.buttonView addSubview:button];
    }
}

/*  ============================================================  */

#pragma mark - 懒加载控件 -
- (LYLInfiniteDisplayView *)infiniteView {
    
    if (!_infiniteView) {
        _infiniteView = [LYLInfiniteDisplayView LYLInfiniteDisplayViewWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 50) delegate:self placeholderImage:[UIImage imageNamed:@"v2_placeholder_full_size"]];
        _infiniteView.delegate = self;
        _infiniteView.pageControlStyle = LYLInfiniteDisplayViewPageContolStyleClassic;
        _infiniteView.pageControlAliment = LYLInfiniteDisplayViewPageContolAlimentRight;
        _infiniteView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _infiniteView.currentPageDotColor = KTHEMES;
        _infiniteView.pageDotColor = [UIColor lightGrayColor];
        _infiniteView.userInteractionEnabled = YES;
    }
    return _infiniteView;
}

- (UIView *)buttonView {
    
    if (!_buttonView) {
        _buttonView = [[UIView alloc] init];
        _buttonView.backgroundColor = [UIColor whiteColor];
    }
    return _buttonView;
}

/*  ============================================================  */

#pragma mark - 释放控件 -
- (void)dealloc {
    self.infiniteView = nil;
    self.buttonView = nil;
}

@end





